﻿activity_pilgrimage = {
	is_shown = {
		highest_held_title_tier > tier_barony
		is_playable_character = yes
		trigger_if = {
			limit = {
				is_ai = yes
			}
			years_from_game_start >= 3
			OR = {
				short_term_gold >= pilgrimage_base_cost
				AND = {
					government_has_flag = government_is_theocracy
					has_treasury = yes
					short_term_treasury >= pilgrimage_base_cost
				}
			}
			trigger_if = { # Throttle Counts
				limit = {
					highest_held_title_tier = tier_county
					NOR = {
						government_has_flag = government_is_mandala
						rite = { rite_has_parameter = mandatory_hajj }
						government_is_japanese_trigger = yes
					}
				}
				OR = {
					ai_zeal >= 100
					has_character_modifier = pam_sf_demon_torment_modifier
				}
			}
		}
		ai_activity_war_check = yes
		ai_activity_coronation_check = yes
	}

	can_start_showing_failures_only = {
		NOT = { is_activity_type_on_cooldown = activity_pilgrimage }
		is_available_adult = yes
		rite = { NOT = { rite_has_parameter = forbidden_from_pilgrimage } }
		faith = { any_holy_site_barony = { exists = this } }
		#Check if all of your holy sites are on cooldown
		trigger_if = {
			limit = {
				any_memory = {
					has_variable = pilgrimage_destination
					memory_age_years < 5
				}
			}
			custom_tooltip = { 
				text = activity_pilgrimage.is_activity_available.all_holy_sites_on_cooldown
				faith = {
					any_holy_site_barony = {
						save_temporary_scope_as = site_check
						NOT = {
							root = {
								any_memory = {
									has_variable = pilgrimage_destination
									memory_age_years < 5
									var:pilgrimage_destination.barony = scope:site_check
								}
							}
						}
						add_to_temporary_list = holy_sites_not_on_cooldown
						any_in_list = {
							list = holy_sites_not_on_cooldown
							count > 0
						}
					}
				}
			}
		}
		trigger_else = { always = yes }
		# If a destination has been selected in the planner, it must not be on cooldown.
		trigger_if = {
			limit = { exists = scope:province }
			custom_tooltip = {
				text = activity_pilgrimage.is_location_valid.recently_visited
				NOT = {
					any_memory = {
						has_variable = pilgrimage_destination
						var:pilgrimage_destination = scope:province
						memory_age_years < 5
					}
				}
			}
		}
		#Are you mandatory Hajj and Mecca is your capital?
		trigger_if = {
			limit = { 
				rite = { rite_has_parameter = mandatory_hajj }
				capital_province.barony ?= title:b_makka
				is_landless_adventurer = no
			}
			custom_tooltip = {
				text = activity_pilgrimage.is_location_valid.capital_is_mecca
				has_trait = hajjaj
			}
		}
		#Are you a diarch forbidden from leaving the realm?
		trigger_if = {
			limit = { bannable_serving_diarch_trigger = yes }
			custom_tooltip = {
				text = activity_pilgrimage.serving_diarch
				faith = {
					any_holy_site_barony = {
						save_temporary_scope_as = site_check
						NOT = {
							root = {
								any_memory = {
									has_variable = pilgrimage_destination
									memory_age_years < 5
									var:pilgrimage_destination.barony = scope:site_check
								}
							}
						}
						add_to_temporary_list = holy_sites_not_on_cooldown
						any_in_list = {
							list = holy_sites_not_on_cooldown
							county.holder = {
								any_liege_or_above = { this = root.liege }
							}
							count > 0
						}
					}
				}
			}
		}
	}

	is_valid = {
		scope:host = {
			#If you don't have a capital to return to, don't bother
			exists = capital_province
			is_physically_able_adult = yes
			is_playable_character = yes
			#Invalidate flag, until/unless this is fixed in code
			NOT = { has_variable = pilgrimage_invalidated_illness }
			#Don't change your capital to be the holy site destination
			trigger_if = {
				limit = { is_landless_adventurer = no }
				capital_province.barony != scope:activity.activity_location.barony
			}
		}
		# Converting mid-pilgrimage is a big no-no.
		scope:activity = {
			OR = {
				NOT = { has_variable = starting_faith }
				# We could check whether the place you're going to is still a holy site in the new faith, but then that messes up all the people moving with you, so we just cancel the whole thing.
				scope:host.faith = var:starting_faith
			}
		}
	}

	on_invalidated = {
		scope:host = {
			#We're heading back home to bury the old host
			if = {
				limit = { has_variable = pilgrimage_death_turn_back }
				trigger_event = pilgrimage.0042
			}
			#Regular invalidation event
			else = {
				if = {
					limit = { capital_province.barony ?= scope:activity.activity_location.barony }
					set_variable = {
						name = moved_capital_to_holy_site
						value = scope:activity.activity_location
					}
				}
				trigger_event = pilgrimage.0040
			}
		}
		invalidation_imprisoned_effect = yes
		invalidation_incapable_effect = yes
		invalidation_host_isolated_effect = yes
	}

	on_host_death = {
		#Make the player heir the new host, if they're on the Pilgrimage
		if = {
			limit = { 
				exists = scope:host.player_heir
				any_attending_character = { this = scope:host.player_heir }
				scope:host.faith = scope:host.player_heir.faith
			}
			scope:host = { save_scope_as = old_host }
			scope:host.player_heir = { save_scope_as = new_host }
			#Also inherit the travel plan
			if = {
				limit = {
					scope:host.current_travel_plan = {
						any_entourage_character = { this = scope:new_host }
					}
				}
				scope:host.current_travel_plan = { set_travel_plan_owner = scope:new_host }
			}
			set_activity_host = scope:new_host
			scope:new_host = {
				set_variable = {
					name = old_host_to_be_buried
					value = scope:old_host #The old host
				}
				add_character_flag = pilgrimage_dealing_with_invalidation
				trigger_event = activity_system.0081
			}
		}
		#Otherwise indirectly cancel the activity by not setting a new host
		else = {
			# Send your entourage home
			scope:host = {
				current_travel_plan = {
					every_entourage_character = { set_location_to_default = yes }
				}
			}
		}
	}

	#Filtering for Mecca will not work if put under Phase instead of the Activity setup
	is_location_valid = {
		# Holy site cooldown should block province selection (map color/click) just like pin selection.
		trigger_if = {
			limit = {
				scope:host = {
					any_memory = {
						has_variable = pilgrimage_destination
						var:pilgrimage_destination = root #root is the province we're checking
						memory_age_years < 5
						save_temporary_scope_as = pilgrimage_holy_site_cooldown_memory
					}
				}
			}
			trigger_if = {
				limit = {
					scope:pilgrimage_holy_site_cooldown_memory = {
						has_variable = pilgrimage_holy_site_cooldown
					}
				}
				custom_tooltip = {
					text = activity_pilgrimage.is_location_valid.recently_visited
					always = no
				}
				custom_tooltip = {
					text = pilgrimage_holy_site_cooldown_until_tt
					always = no
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = activity_pilgrimage.is_location_valid.recently_visited
					always = no
				}
			}
		}

		#Hajj only goes to Mecca
		trigger_if = {
			limit = {
				scope:special_option ?= flag:pilgrimage_type_hajj
				exists = barony
			}
			custom_tooltip = {
				text = activity_pilgrimage.is_location_valid.hajj_mecca
				barony = title:b_makka
			}
		}
		#You can't pilgrimage to your own capital - Except for if you are an adventurer because then you travel around all the time anyway
		trigger_if = {
			limit = {
				scope:host = { is_landless_adventurer = no }
			}
			custom_tooltip = {
				text = activity_pilgrimage.is_location_valid.capital_is_holy_site
				scope:host.capital_province != root
			}
		}

		# If you are supposed to be the realm's reserve ruler, then you can't take a multi-year foreign trip.
		trigger_if = {
			limit = {
				scope:host = { bannable_serving_diarch_trigger = yes }
			}
			custom_tooltip = {
				text = activity_pilgrimage.serving_diarch
				county.holder = {
					OR = {
						any_liege_or_above = { this = scope:host.liege }
						this = scope:host.liege
					}
				}
			}
		}

		trigger_if = {
			limit = {
				scope:host = {
					is_ai = yes
					has_title = title:h_china
				}
			}
			county.holder.top_liege = scope:host
		}
	}

	province_description = {
		desc = activity_pilgrimage_province_desc
		# Are you going to honor your imaginary friend guardian angel?
		triggered_desc = {
			trigger = {
				scope:host = {
					any_owned_story = {
						type = story_cycle_imaginary_friend
						var:pilgrimage_destination ?= root
					}
				}
			}
			desc = activity_pilgrimage_imaginary_friend_location_desc
		}
		#Is it an unvisited holy site?
		triggered_desc = {
			trigger = {
				scope:host = {
					OR = {
						AND = {
							#These two really shouldn't exist without each other, but safe-checking
							NOT = { 
								exists = var:visited_unique_holy_sites_list
								exists = var:visited_unique_holy_sites_count 
							}
						}
						AND = {
							exists = var:visited_unique_holy_sites_count
							#Does this holy site exist in the list?
							NOT = {
								any_in_list = {
									variable = visited_unique_holy_sites_list
									this = root 
								}
							}

						}
					}
				}
			}
			desc = activity_pilgrimage_province_unvisited_desc
		}
		# Is it a unique holy site? (does it have bespoke events, even if minor)
		triggered_desc = {
			trigger = {
				OR = {
					#Taken from the Pilgrimage arrival on_action event triggers
					#Christianity
					AND = {
						scope:host = { religion = religion:christianity_religion }
						OR = {
							county = title:c_roma # Rome
							county = title:c_jerusalem # Jerusalem
							county = title:c_byzantion # Constantinople
							county = title:c_alexandria # Alexandria
						}
					}
					#Judaism
					AND = {
						scope:host = { religion = religion:judaism_religion }
						OR = {
							county = title:c_sinai # Mt. Sinai
							county = title:c_jerusalem # Jerusalem
						}
					}
					#Islam
					AND = {
						scope:host = { religion = religion:islam_religion }
						OR = {
							county = title:c_mecca # Mecca
							county = title:c_medina # Medina
							county = title:c_sinai # Mt. Sinai
							county = title:c_jerusalem # Jerusalem
						}
					}
					#Hinduism
					AND = {
						scope:host = { religion = religion:hinduism_religion }
						OR = {
							county = title:c_varanasi # Varanasi
							county = title:c_ayodhya # Ayodhya
							county = title:c_mathura # Mathura
							county = title:c_sthanisvara # Haridwar
							county = title:c_kanchipuram # Kanchipuram
							county = title:c_ujjayini # Ujjayini
							county = title:c_dvaraka # Dwarka
						}
					}
					#Buddhism
					AND = {
						scope:host = { religion = religion:buddhism_religion }
						OR = {
							county = title:c_gaya # Bodh Gaya
							county = title:c_kusinagara # Kusinagara
							county = title:c_varanasi # Sarnath
						}
					}
					#Jainism
					AND = {
						scope:host = { religion = religion:jainism_religion }
						county = title:c_radha # Shikharj

					}
					#Zoroastrian
					AND = {
						scope:host = { religion = religion:zoroastrianism_religion }
						county = title:c_baduspan # Ushi-darena

					}
					#Norse
					AND = {
						scope:host = { religion = religion:germanic_religion }
						county = title:c_paderborn # Paderborn

					}
				}
			}
			desc = activity_pilgrimage_province_unique_desc
		}
		# Is it an eminent holy site?
		triggered_desc = {
			trigger = {
				scope:host.faith = {
					any_eminent_holy_site = {
						holy_site_county =  root.county
					}
				}
			}
			desc = activity_pilgrimage_eminent_holy_site_desc
		}
		# Inspection modifier
		triggered_desc = {
			trigger = {
				OR = {
					has_province_modifier = inspection_protected_holy_site_levy_modifier
					has_province_modifier = inspection_protected_holy_poi_levy_modifier
					has_province_modifier = inspection_protected_holy_site_gold_modifier
					has_province_modifier = inspection_protected_holy_poi_gold_modifier
				}
			}
			desc = activity_pilgrimage_province_desc_inspection_modifier
		}

		#What's the distance to the holy site - needs to be in the middle of the PROVINCE_DESCRIPTION since it move from the negative itinerary to the Additional Cost-part
		first_valid = {
			triggered_desc = {
				trigger = { "scope:host.capital_province.squared_distance(root)" <= squared_distance_small }
				desc = activity_pilgrimage_province_very_short_desc
			}
			triggered_desc = {
				trigger = { 
					"scope:host.capital_province.squared_distance(root)" > squared_distance_small
					"scope:host.capital_province.squared_distance(root)" <= squared_distance_medium
				}
				desc = activity_pilgrimage_province_pretty_short_desc
			}
			triggered_desc = {
				trigger = { 
					"scope:host.capital_province.squared_distance(root)" > squared_distance_medium
					"scope:host.capital_province.squared_distance(root)" <= squared_distance_large
				}
				desc = activity_pilgrimage_province_short_desc
			}
			triggered_desc = {
				trigger = { 
					"scope:host.capital_province.squared_distance(root)" > squared_distance_large
					"scope:host.capital_province.squared_distance(root)" <= squared_distance_huge
				}
				desc = activity_pilgrimage_province_intermediate_desc
			}
			triggered_desc = {
				trigger = { 
					"scope:host.capital_province.squared_distance(root)" > squared_distance_huge
					"scope:host.capital_province.squared_distance(root)" <= squared_distance_almost_massive
				}
				desc = activity_pilgrimage_province_respectably_desc
			}
			triggered_desc = {
				trigger = { 
					"scope:host.capital_province.squared_distance(root)" > squared_distance_almost_massive
					"scope:host.capital_province.squared_distance(root)" <= squared_distance_massive
				}
				desc = activity_pilgrimage_province_quite_far_desc
			}
			#Klingenberg -> Jerusalem
			triggered_desc = {
				trigger = { 
					"scope:host.capital_province.squared_distance(root)" > squared_distance_massive
					"scope:host.capital_province.squared_distance(root)" <= squared_distance_monstrous
				}
				desc = activity_pilgrimage_province_very_far_desc
			}
			#Klingenberg -> Kanchipuram
			triggered_desc = {
				trigger = { "scope:host.capital_province.squared_distance(root)" > squared_distance_monstrous }
				desc = activity_pilgrimage_province_extraordinarily_far_desc
			}
			#Fallback, we should never end up here
			desc = activity_pilgrimage_province_desc
		}
		#Once again, with feeling - needs to be at the end of the PROVINCE_DESCRIPTION since it has the Effects-part
		first_valid = {
			triggered_desc = {
				trigger = { 
					scope:host.capital_province = {
						squared_distance = {
							target = root
							value > long_pilgrimage_max_length
						}
					}
				}
				desc = activity_pilgrimage_province_very_long_mult_desc
			}
			triggered_desc = {
				trigger = { 
					scope:host.capital_province = {
						squared_distance = {
							target = root
							value > medium_pilgrimage_max_length
						}
					}
				}
				desc = activity_pilgrimage_province_long_mult_desc
			}
			triggered_desc = {
				trigger = { 
					scope:host.capital_province = {
						squared_distance = {
							target = root
							value > short_pilgrimage_max_length
						}
					}
				}
				desc = activity_pilgrimage_province_medium_mult_desc
			}
		}
	}

	# desc is only shown in debug AI watch window
	ai_will_do = {
		value = 0
		if = {
			limit = {
				ai_energy < 0
			}
			add = {
				add = ai_energy
				desc = "ai_energy"
			}
		}
		if = {
			limit = {
				rite = { rite_has_doctrine = doctrine_pilgrimage_mandatory }
				NOT = { has_trait = pilgrim }
			}
			add = {
				value = 50
				desc = "Pilgrim mandatory malus"
			}
		}
		if = {
			limit = {
				rite = { rite_has_doctrine = doctrine_pilgrimage_mandatory_hajj }
				NOT = { has_trait = hajjaj }
			}
			add = {
				value = 5000
				desc = "Hajj mandatory malus"
			}
		}
		if = {
			limit = { ai_has_pious_builder_personality = yes}
			add = {
				value = 50
				desc = "Pious Builder"
			}
		}
		if = {
			limit = {
				OR = {
					short_term_gold >= major_gold_value
					AND = {
						government_has_flag = government_is_theocracy
						has_treasury = yes
						short_term_treasury >= major_gold_value
					}
				}
			}
			add = {
				value = 30
				desc = "Got gold to burn"
			}
		}
		if = {
			limit = { piety_level <= 2 }
			add = {
				value = 20
				desc = "Has low piety level"
			}
		}
		if = {
			limit = { has_trait = zealous }
			add = {
				value = 20
				desc = "Has Zealous"
			}
		}
		if = {
			limit = { has_trait = humble }
			add = {
				value = 10
				desc = "Has Humble"
			}
		}
		if = {
			limit = {
				ai_zeal > 0
				piety < 0
			}
			add = {
				value = 10
				desc = "Zealous wants above 0 piety"
			}
		}
		if = {
			limit = { 
				has_trait = zealous
				NOT = { has_trait = pilgrim }
			}
			add = {
				value = 20
				desc = "Has Zealous, don't have Pilgrim"
			}
		}
		if = {
			limit = {
				top_liege != this
				has_vassal_stance = zealot
			}
			add = {
				value = 10
				desc = zealot
			}
		}
		if = {
			limit = { 
				government_has_flag = government_is_mandala
				NOT = { 
					has_trait = pilgrim
					has_trait_xp = {
						trait = pilgrim
						value >= 100
					}
				}
			}
			add = {
				value = 100
				desc = "Mandala is not max Pilgrim"
			}
		}
		if = {
			limit = { 
				government_has_flag = government_is_mandala
				NOT = { 
					has_trait = pilgrim
					has_trait_xp = {
						trait = pilgrim
						value >= 100
					}
				}
				has_variable = mandala_godking
			}
			add = {
				value = 400
				desc = "Mandala Godking LET'S GOOO"
			}
		}
		if = {
			limit = {
				OR = {
					has_trait = cynical
					any_secret = { type = secret_non_believer }
				}
			}
			add = {
				value = -30
				desc = "Is cynical or non-believer"
			}
		}
		if = {
			limit = {
				has_trait = pilgrim
				has_trait_xp = {
					trait = pilgrim
					value >= 100
				}
			}
			add = {
				value = -30
				desc = "Has maxed out Pilgrim"
			}
		}
		if = {
			limit = {
				has_pam_dlc_trigger = yes
				faith = { has_variable = pam_secured_pilgrim_routes }
			}
			add = {
				value = 10
				desc = pam_secure_pilgrim_routes_ai_pilgrimage
			}
		}
		add = activity_general_ai_will_do_value
		if = {
			limit = {
				has_character_modifier = promised_pilgrimage_to_clergy_modifier
			}
			add = {
				value = 1000
				desc = promised_pilgrimage_to_clergy_modifier
			}
		}
		if = {
			limit = {
				has_character_modifier = pam_sf_demon_torment_modifier
			}
			add = {
				value = 1000
				desc = pam_sf_demon_torment_modifier
			}
		}
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 60
		duchy = 60
		kingdom = 60
		empire = 60
		hegemony = 60
	}

	ai_will_select_province = {
		value = 50
		if = {
			limit = {
				scope:host = {
					exists = var:visited_unique_holy_sites_count
					var:visited_unique_holy_sites_count > 0
					NOT = {
						any_in_list = {
							variable = visited_unique_holy_sites_list
							this = root
						}
					}
				}
			}
			add = {
				value = 100
				desc = "Unvisited holy site"
			}
		}
		if = {
			limit = { "scope:host.capital_province.squared_distance(root)" <= squared_distance_small }
			multiply = {
				value = 8
				desc = "Holy site is super close 8"
			}
		}
		else_if = {
			limit = {
				"scope:host.capital_province.squared_distance(root)" > squared_distance_small
				"scope:host.capital_province.squared_distance(root)" <= squared_distance_medium
			}
			multiply = {
				value = 7
				desc = "Holy site is pretty close 7"
			}
		}
		else_if = {
			limit = {
				"scope:host.capital_province.squared_distance(root)" > squared_distance_medium
				"scope:host.capital_province.squared_distance(root)" <= squared_distance_large
			}
			multiply = {
				value = 6
				desc = "Holy site is OK close 6"
			}
		}
		else_if = {
			limit = {
				"scope:host.capital_province.squared_distance(root)" > squared_distance_large
				"scope:host.capital_province.squared_distance(root)" <= squared_distance_huge
			}
			multiply = {
				value = 5
				desc = "Holy site is intermediately far away 5"
			}
		}
		else_if = {
			limit = {
				"scope:host.capital_province.squared_distance(root)" > squared_distance_huge
				"scope:host.capital_province.squared_distance(root)" <= squared_distance_almost_massive
			}
			multiply = {
				value = 4
				desc = "Holy site is quite far away 4"
			}
		}
		else_if = {
			limit = {
				"scope:host.capital_province.squared_distance(root)" > squared_distance_almost_massive
				"scope:host.capital_province.squared_distance(root)" <= squared_distance_massive
			}
			multiply = {
				value = 3
				desc = "Holy site is far away 3"
			}
		}
		#Klingenberg -> Jerusalem
		else_if = {
			limit = {
				"scope:host.capital_province.squared_distance(root)" > squared_distance_massive
				"scope:host.capital_province.squared_distance(root)" <= squared_distance_monstrous
			}
			multiply = {
				value = 2
				desc = "Holy site is very far away 2"
			}
		}
		#Klingenberg -> Kanchipuram
		else_if = {
			limit = { "scope:host.capital_province.squared_distance(root)" > squared_distance_monstrous }
			multiply = {
				value = 1
				desc = "Holy site is super far away 1"
			}
		}
		# Plague
		if = {
			limit = {
				any_province_epidemic = { }
			}
			add = {
				value = -200
				desc = "Plague in Destination"
			}
		}
	}

	###################
	# PARAMETERS
	###################

	is_single_location = yes

	province_filter = holy_sites

	max_route_deviation_mult = 3.0

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					OR = {
						has_treasury = no
						NOT = { government_has_flag = government_is_theocracy }
					}
				}
				add = pilgrimage_activity_cost_value
				if = {
					limit = {
						has_title = title:e_minister_of_revenue
					}
					multiply = 0.85
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					government_has_flag = government_is_theocracy
					has_treasury = yes
				}
				add = pilgrimage_activity_cost_value
				if = {
					limit = {
						has_title = title:e_minister_of_revenue
					}
					multiply = 0.85
				}
			}
		}
	}

	ui_predicted_cost = {
		gold = {
			if = {
				limit = {
					government_has_flag = government_is_theocracy
					has_treasury = yes
				}
				value = 0
			}
			else = {
			# Calculate average cost of traveling to one of your holy sites
			faith = { 
				# Calculate a summation of the costs to travel to each of your faith's holy sites
				# MUST BE SYNCED WITH THE PHASE COST
				every_holy_site_barony = {
					#Tier 1
					if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_small
							"squared_distance(root.capital_province)" <= squared_distance_medium
						}
						add = {
							value = root.medium_gold_value 
							multiply = 0.2
						}
					}
					#Tier 2: Praha -> Cologne
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_medium
							"squared_distance(root.capital_province)" <= squared_distance_large
						}
						add = {
							value = root.medium_gold_value 
							multiply = 0.4
						}
					}
					#Tier 3
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_large
							"squared_distance(root.capital_province)" <= squared_distance_huge
						}
						add = {
							value = root.medium_gold_value 
							multiply = 0.6
						}
					}
					#Tier 4
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_huge
							"squared_distance(root.capital_province)" <= squared_distance_almost_massive
						}
						add = {
							value = root.medium_gold_value 
							multiply = 0.8
						}
					}
					#Tier 5
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_almost_massive
							"squared_distance(root.capital_province)" <= squared_distance_massive
						}
						add = {
							value = root.medium_gold_value 
							multiply = 1
						}
					}
					#Tier 6: Klingenberg -> Jerusalem
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_massive
							"squared_distance(root.capital_province)" <= squared_distance_monstrous
						}
						add = {
							value = root.medium_gold_value 
							multiply = 1.2
						}
					}
					#Tier 7: Klingenberg -> Kanchipuram
					else_if = {
						limit = { "squared_distance(root.capital_province)" > squared_distance_monstrous }
						add = {
							value = root.medium_gold_value 
							multiply = 1.5
						}
					}
				}
			}

			# Now that we have added up the costs of traveling to every holy site, we divide by the number of holy sites you have so we come up with an average travel cost value
			divide = {
				# Have to set this value to 1 so the error log doesn't think we're dividing by 0
				value = 1
				faith = {
					every_holy_site_barony = {
						add = 1
					}
				}
				# account for the starting value of 1
				subtract = 1
				# Ensure that we never drop to 0
				min = 1
			}

			add = { # Base cost, scaled by era
				value = pilgrimage_base_cost
				multiply = activity_cost_scale_by_era
			}
			
			# Options 
			add = { # Pomp Option 
				value = 0 # Appropriate Cost
				add = -10 # Humble Cost
				add = 50 # Ceremonial Cost
				add = 100 # Throng Cost
				# Scale option costs by tier and era
				multiply = activity_cost_scale_by_tier
				multiply = activity_cost_scale_by_era
				# Divide by the number of option levels to get an average option cost
				divide = 4
			}

			if = {
				limit = { has_character_modifier = ghost_pilgrimage_promised_modifier }
				subtract = {
					value = medium_gold_value
					desc = pilgrimage_cost_triggered_by_ghosts
				}
			}
			#You should really only have this flag if your religion has Hajj and you've never Hajj'd
			if = {
				limit = { has_character_modifier = hajj_promised_modifier }
				subtract = {
					value = medium_gold_value
					desc = pilgrimage_cost_triggered_by_dead_hajj_relative
				}
			}
			#You should really only have this flag if you haven't Pilgrim'd before
			if = {
				limit = { has_character_modifier = pilgrimage_promised_modifier }
				subtract = {
					value = medium_gold_value
					desc = pilgrimage_cost_triggered_by_dead_pilgrimage_relative
				}
			}
			if = {
				limit = {
					dynasty ?= { has_dynasty_perk = ep2_activities_legacy_1 }
				}
				subtract = {
					value = pilgrimage_base_cost
					multiply = ep2_activities_legacy_1_pilgrimages_discount_value
					desc = ep2_activities_legacy_track
				}
			}
			#court.8140
			if = {
				limit = {
					has_character_flag = court_event_discount_pilgrimage
				}
				multiply = {
					value = 0.75
				}
			}
			# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) halves every cost.
			if = {
				limit = {
					has_character_modifier = pam_sf_pilgrimage_funded_modifier
				}
				multiply = {
					value = 0.5
				}
			}
			if = {
				limit = {
					OR = {
						has_fulfillment_parameter = sp_cheaper_pilgrimage_major
						has_fulfillment_parameter = sp_cheaper_pilgrimage
					}
				}
				multiply = {
					value = spiritual_fulfillment_pilgrimage_cost_mult
				}
			}
			if = {
				limit = {
					has_government = landless_adventurer_government
					has_perk = clerical_justifications_perk
				}
				multiply = {
					value = 0.25
					desc = adventurer_discount_desc
				}
			}
			if = {
				limit = {
					rite = { rite_has_parameter = local_shrine_offering }
				}
				multiply = {
					value = 1.75
					desc = doctrine_pilgrimage_local_rites_name
				}
			}
			if = {
				limit = {
					confederation ?= { has_cohesion_level_parameter = any_member_activity_cost_reduced }
				}
				multiply = {
					value = 0.9
					desc = CB_COHESION_PARAMETER_DISCOUNT
				}
			}
			if = {
				limit = {
					var:tgp_ceremonial_liege_events_0020_discount ?= flag:pilgrimage
				}
				multiply = {
					value = 0.85
					desc = tgp_ceremonial_liege_events_0020_discount_desc
				}
			}
			min = minor_gold_value
			
			# Make it a multiple of 5 (rounded up)
			divide = 5
			ceiling = yes 
			multiply = 5
			if = {
				limit = {
					has_title = title:e_minister_of_revenue
				}
				multiply = 0.85
			}
		
			}
		}
		treasury = {
			if = {
				limit = {
					OR = {
						has_treasury = no
						NOT = { government_has_flag = government_is_theocracy }
					}
				}
				value = 0
			}
			else = {
			# Calculate average cost of traveling to one of your holy sites
			faith = { 
				# Calculate a summation of the costs to travel to each of your faith's holy sites
				# MUST BE SYNCED WITH THE PHASE COST
				every_holy_site_barony = {
					#Tier 1
					if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_small
							"squared_distance(root.capital_province)" <= squared_distance_medium
						}
						add = {
							value = root.medium_gold_value 
							multiply = 0.2
						}
					}
					#Tier 2: Praha -> Cologne
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_medium
							"squared_distance(root.capital_province)" <= squared_distance_large
						}
						add = {
							value = root.medium_gold_value 
							multiply = 0.4
						}
					}
					#Tier 3
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_large
							"squared_distance(root.capital_province)" <= squared_distance_huge
						}
						add = {
							value = root.medium_gold_value 
							multiply = 0.6
						}
					}
					#Tier 4
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_huge
							"squared_distance(root.capital_province)" <= squared_distance_almost_massive
						}
						add = {
							value = root.medium_gold_value 
							multiply = 0.8
						}
					}
					#Tier 5
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_almost_massive
							"squared_distance(root.capital_province)" <= squared_distance_massive
						}
						add = {
							value = root.medium_gold_value 
							multiply = 1
						}
					}
					#Tier 6: Klingenberg -> Jerusalem
					else_if = {
						limit = {
							"squared_distance(root.capital_province)" > squared_distance_massive
							"squared_distance(root.capital_province)" <= squared_distance_monstrous
						}
						add = {
							value = root.medium_gold_value 
							multiply = 1.2
						}
					}
					#Tier 7: Klingenberg -> Kanchipuram
					else_if = {
						limit = { "squared_distance(root.capital_province)" > squared_distance_monstrous }
						add = {
							value = root.medium_gold_value 
							multiply = 1.5
						}
					}
				}
			}

			# Now that we have added up the costs of traveling to every holy site, we divide by the number of holy sites you have so we come up with an average travel cost value
			divide = {
				# Have to set this value to 1 so the error log doesn't think we're dividing by 0
				value = 1
				faith = {
					every_holy_site_barony = {
						add = 1
					}
				}
				# account for the starting value of 1
				subtract = 1
				# Ensure that we never drop to 0
				min = 1
			}

			add = { # Base cost, scaled by era
				value = pilgrimage_base_cost
				multiply = activity_cost_scale_by_era
			}
			
			# Options 
			add = { # Pomp Option 
				value = 0 # Appropriate Cost
				add = -10 # Humble Cost
				add = 50 # Ceremonial Cost
				add = 100 # Throng Cost
				# Scale option costs by tier and era
				multiply = activity_cost_scale_by_tier
				multiply = activity_cost_scale_by_era
				# Divide by the number of option levels to get an average option cost
				divide = 4
			}

			if = {
				limit = { has_character_modifier = ghost_pilgrimage_promised_modifier }
				subtract = {
					value = medium_gold_value
					desc = pilgrimage_cost_triggered_by_ghosts
				}
			}
			#You should really only have this flag if your religion has Hajj and you've never Hajj'd
			if = {
				limit = { has_character_modifier = hajj_promised_modifier }
				subtract = {
					value = medium_gold_value
					desc = pilgrimage_cost_triggered_by_dead_hajj_relative
				}
			}
			#You should really only have this flag if you haven't Pilgrim'd before
			if = {
				limit = { has_character_modifier = pilgrimage_promised_modifier }
				subtract = {
					value = medium_gold_value
					desc = pilgrimage_cost_triggered_by_dead_pilgrimage_relative
				}
			}
			if = {
				limit = {
					dynasty ?= { has_dynasty_perk = ep2_activities_legacy_1 }
				}
				subtract = {
					value = pilgrimage_base_cost
					multiply = ep2_activities_legacy_1_pilgrimages_discount_value
					desc = ep2_activities_legacy_track
				}
			}
			#court.8140
			if = {
				limit = {
					has_character_flag = court_event_discount_pilgrimage
				}
				multiply = {
					value = 0.75
				}
			}
			# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) halves every cost.
			if = {
				limit = {
					has_character_modifier = pam_sf_pilgrimage_funded_modifier
				}
				multiply = {
					value = 0.5
				}
			}
			if = {
				limit = {
					OR = {
						has_fulfillment_parameter = sp_cheaper_pilgrimage_major
						has_fulfillment_parameter = sp_cheaper_pilgrimage
					}
				}
				multiply = {
					value = spiritual_fulfillment_pilgrimage_cost_mult
				}
			}
			if = {
				limit = {
					has_government = landless_adventurer_government
					has_perk = clerical_justifications_perk
				}
				multiply = {
					value = 0.25
					desc = adventurer_discount_desc
				}
			}
			if = {
				limit = {
					rite = { rite_has_parameter = local_shrine_offering }
				}
				multiply = {
					value = 1.75
					desc = doctrine_pilgrimage_local_rites_name
				}
			}
			if = {
				limit = {
					confederation ?= { has_cohesion_level_parameter = any_member_activity_cost_reduced }
				}
				multiply = {
					value = 0.9
					desc = CB_COHESION_PARAMETER_DISCOUNT
				}
			}
			if = {
				limit = {
					var:tgp_ceremonial_liege_events_0020_discount ?= flag:pilgrimage
				}
				multiply = {
					value = 0.85
					desc = tgp_ceremonial_liege_events_0020_discount_desc
				}
			}
			min = minor_gold_value
			
			# Make it a multiple of 5 (rounded up)
			divide = 5
			ceiling = yes 
			multiply = 5
			if = {
				limit = {
					has_title = title:e_minister_of_revenue
				}
				multiply = 0.85
			}
		
			}
		}
	}

	###################
	# OPTIONS
	###################

	options = {
		#########
		# TYPE OF PILGRIMAGE [SPECIAL TYPE] OPTION
		#########
		special_type = {
			pilgrimage_type_pious = {
				#Crashes [sometimes] if you start the game with a ruler where this is default then tag over to another ruler where this isn't default
				default = {
					OR = {
						NOT = { 
							rite = { rite_has_parameter = mandatory_hajj }
						}
						has_trait = hajjaj
					}
				}
				is_valid = {
					# Most Muslims must perform the Hajj first.
					trigger_if = {
						limit = {
							rite = { rite_has_parameter = mandatory_hajj }
						}
						custom_tooltip = {
							text = activity_pilgrimage.is_valid.islam.must_complete_hajj_first
							has_trait = hajjaj
						}
					}
					# Otherwise, you can always do this.
					trigger_else = { always = yes }
				}
				ai_will_do = {
					value = 50
					if = {
						limit = {
							OR = {
								has_trait = zealous
								has_trait = diligent
								has_trait = flagellant
								has_trait = brave
							}
						}
						add = 50
					}
					if = {
						limit = {
							OR = {
								has_trait = cynical
								has_trait = lazy
								has_trait = craven
							}
							any_secret = { type = secret_non_believer }
						}
						subtract = 50
					}
				}
			}
			pilgrimage_type_worldly = {
				is_valid = {
					# Most Muslims must perform the Hajj first.
					trigger_if = {
						limit = {
							rite = { rite_has_parameter = mandatory_hajj }
						}
						custom_tooltip = {
							text = activity_pilgrimage.is_valid.islam.must_complete_hajj_first
							has_trait = hajjaj
						}
					}
					# Otherwise, you can always do this.
					trigger_else = { always = yes }
				}
				ai_will_do = {
					value = 50
					if = {
						limit = {
							OR = {
								has_trait = cynical
								has_trait = lazy
								has_trait = craven
							}
							any_secret = { type = secret_non_believer }
						}
						add = 50
					}
					if = {
						limit = {
							OR = {
								has_trait = zealous
								has_trait = diligent
								has_trait = flagellant
								has_trait = brave
							}
						}
						subtract = 50
					}
				}
			}
			pilgrimage_type_hajj = {
				#Crashes [sometimes] if you start the game with a ruler where this is default then tag over to another ruler where this isn't default
				default = {
					rite = { rite_has_parameter = mandatory_hajj }
					NOT = { has_trait = hajjaj }
				}
				is_shown = {
					OR = {
						rite = { rite_has_parameter = mandatory_hajj }
						can_perform_the_hajj_trigger = yes
					}
				}
				is_valid = {
					# You only get to Hajj every X years.
					trigger_if = {
						limit = {
							exists = capital_province
							NOT = { capital_province.barony = title:b_makka }
						}
						custom_tooltip = {
							text = activity_pilgrimage.is_valid.hajjed_recently
							NOT = {
								any_memory = {
									memory_type = completed_hajj_memory
									memory_age_years < hajj_cooldown_value
								}
							}
						}
					}
					OR = {
						rite = { rite_has_parameter = mandatory_hajj }
						can_perform_the_hajj_trigger = yes
					}
					#Is Mecca your capital?
					custom_tooltip = {
						text = activity_pilgrimage.is_location_valid.capital_is_mecca
						NAND = {
							exists = capital_province
							capital_province.barony = title:b_makka
							is_landless_adventurer = no
						}
					}
				}
				ai_will_do = {
					value = 50
					if = {
						limit = {
							rite = { rite_has_parameter = mandatory_hajj }
							NOT = { has_trait = hajjaj }
						}
						add = 5000
					}
					if = {
						limit = {
							OR = {
								has_trait = zealous
								has_trait = diligent
								has_trait = flagellant
								has_trait = brave
							}
						}
						add = 50
					}
					if = {
						limit = {
							OR = {
								has_trait = cynical
								has_trait = lazy
								has_trait = craven
							}
							any_secret = { type = secret_non_believer }
						}
						subtract = 50
					}
				}
			}
		}
		#########
		# LEVEL OF DEVOTION OPTION
		#########
		pilgrimage_option_fidelity = {
			pilgrimage_fidelity_obligatory = {
				is_shown = { has_dlc_feature = advanced_activities }

				is_valid = {
					trigger_if = {
						limit = { religion = religion:islam_religion }
						custom_tooltip = {
							text = activity_pilgrimage.is_valid.islam.mandatory_or_impatient
							OR = {
								rite = { rite_has_parameter = mandatory_hajj }
								has_trait = impatient
							}
						}
					}
					trigger_else = {
						custom_tooltip = {
							text = activity_pilgrimage.is_valid.other.mandatory_or_impatient
							OR = {
								rite = { rite_has_parameter = mandatory_pilgrimage }
								has_trait = impatient
							}
						}
					}
				}

				# Travel modifier given in on_enter_travel_state.

				ai_will_do = {
					value = 0
					# AI values.
					add = {
						value = ai_zeal
						multiply = -1
					}
					# Basic weight-up.
					if = {
						limit = {
							OR = {
								# Some personality traits.
								has_trait = impatient
								has_trait = cynical
								# Reclusive characters want this over with quickly.
								has_trait = reclusive
								# Diligent characters want to be on their way unless they regard religion very seriously.
								AND = {
									has_trait = diligent
									NOT = { has_trait = zealous }
								}
								# Non-believers want out of here.
								any_secret = { type = secret_non_believer }
							}
						}
						add = 100
					}
					# Basic weight-down.
					if = {
						limit = {
							OR = {
								# Some personality traits.
								has_trait = patient
								has_trait = zealous
								# Flagellants take their time on the trail.
								has_trait = flagellant
								# Diligent characters who take religion very seriously don't want to be dishonest about a pilgrimage.
								AND = {
									has_trait = diligent
									has_trait = zealous
								}
							}
						}
						add = -100
					}
				}
			}
			pilgrimage_fidelity_pilgrim = {
				default = yes

				ai_will_do = {
					# Default to this.
					value = 100
				}
			}
			pilgrimage_fidelity_contemplative = {
				is_shown = { has_dlc_feature = advanced_activities }

				is_valid = {
					custom_tooltip = {
						text = activity_pilgrimage.is_valid.pilgrim_or_patient
						OR = {
							has_trait = patient
							has_trait = pilgrim
							has_trait = hajjaj
						}
					}
				}

				# Travel modifier given in on_enter_travel_state.

				ai_will_do = {
					value = 0
					# AI values.
					add = {
						value = ai_zeal
						multiply = 1
					}
					# Basic weight-up.
					if = {
						limit = {
							OR = {
								# Some personality traits.
								has_trait = patient
								has_trait = zealous
								# Flagellants take their time on the trail.
								has_trait = flagellant
								# Diligent characters who take religion very seriously want to be thorough
								AND = {
									has_trait = diligent
									has_trait = zealous
								}
							}
						}
						add = 100
					}
					# Basic weight-down.
					if = {
						limit = {
							OR = {
								# Some personality traits.
								has_trait = impatient
								has_trait = cynical
								# Reclusive characters want this over with quickly.
								has_trait = reclusive
								# Diligent characters want to be on their way unless they regard religion very seriously.
								AND = {
									has_trait = diligent
									NOT = { has_trait = zealous }
								}
								# Non-believers want out of here.
								any_secret = { type = secret_non_believer }
							}
						}
						add = -100
					}
				}
			}
		}
		#########
		# POMP OPTION
		#########
		pilgrimage_option_pomp = {
			pilgrimage_pomp_humble = {
				is_shown = { has_dlc_feature = advanced_activities }
				default = {
					has_personal_tenet_flag = tenet_vows_of_poverty_humble_host
				}

				cost = {
					gold = {
						if = {
							limit = {
								government_has_flag = government_is_theocracy
								has_treasury = yes
							}
							value = 0
						}
						else = {
							subtract = {
								desc = pilgrimage_cost_pomp_ceremonial
								add = {
									value = 10
									desc = pilgrimage_cost_pomp_ceremonial
								}
								add = {
									value = 10 
									multiply = activity_cost_scale_by_tier
									subtract = 10
									desc = activity_cost_scale_by_tier_desc
								}
								add = {
									value = 10 
									multiply = activity_cost_scale_by_era
									subtract = 10 
									desc = activity_cost_scale_by_era_desc
								}
							}
						}
					}
					treasury = {
						if = {
							limit = {
								OR = {
									has_treasury = no
									NOT = { government_has_flag = government_is_theocracy }
								}
							}
							value = 0
						}
						else = {
							subtract = {
								desc = pilgrimage_cost_pomp_ceremonial
								add = {
									value = 10
									desc = pilgrimage_cost_pomp_ceremonial
								}
								add = {
									value = 10 
									multiply = activity_cost_scale_by_tier
									subtract = 10
									desc = activity_cost_scale_by_tier_desc
								}
								add = {
									value = 10 
									multiply = activity_cost_scale_by_era
									subtract = 10 
									desc = activity_cost_scale_by_era_desc
								}
							}
						}
					}
				}
				
				# Travel modifier given in on_enter_travel_state.

				# We just grab/generate random same-faith "pilgrims" from the local pool.

				ai_will_do = {
					value = 0
					add = {
						value = 40
						desc = "Base test value"
					}
				}
			}
			pilgrimage_pomp_appropriate = {
				is_valid = {
					trigger_if = {
						limit = { has_dlc_feature = advanced_activities }
						pam_vows_of_poverty_premium_activity_option_valid_trigger = yes
					}
				}
				default = {
					OR = {
						NOT = { has_personal_tenet_flag = tenet_vows_of_poverty_humble_host }
						NOT = { has_dlc_feature = advanced_activities }
					}
				}

				# Entourage option grabbing suitable bodyguards & maybe someone from court who really likes you, + randos.
				travel_entourage_selection = { 
					weight = pilgrimage_entourage_base_set_weighting_value
					max = pilgrimage_entourage_pomp_appropriate_max_value
					invite_rule_order = 1
				}

				ai_will_do = {
					value = 0
					add = {
						value = 40
						desc = "Base test value"
					}
				}
			}
			pilgrimage_pomp_ceremonial = {
				is_shown = { has_dlc_feature = advanced_activities }
				is_valid = {
					pam_vows_of_poverty_premium_activity_option_valid_trigger = yes
				}

				cost = { 
					gold = {
						if = {
							limit = {
								government_has_flag = government_is_theocracy
								has_treasury = yes
							}
							value = 0
						}
						else = {
							add = {
								desc = pilgrimage_cost_pomp_ceremonial
								add = {
									value = 50
									desc = pilgrimage_cost_pomp_ceremonial
								}
								add = {
									value = 50 
									multiply = activity_cost_scale_by_tier
									subtract = 50
									desc = activity_cost_scale_by_tier_desc
								}
								add = {
									value = 50 
									multiply = activity_cost_scale_by_era
									subtract = 50 
									desc = activity_cost_scale_by_era_desc
								}
								if = {
									limit = {
										dynasty ?= { has_dynasty_perk = ep2_activities_legacy_1 }
									}
									subtract = {
										value = 50
										multiply = ep2_activities_legacy_1_pilgrimages_discount_value
										desc = ep2_activities_legacy_track
									}
								}
								if = {
									limit = {
										has_perk = journey_planner_perk
									}
									multiply = {
										value = voyager_journey_planner_value
										desc = journey_planner_perk_name
									}
								}
								# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) halves this pomp cost.
								if = {
									limit = {
										has_character_modifier = pam_sf_pilgrimage_funded_modifier
									}
									multiply = {
										value = 0.5
										desc = pam_sf_pilgrimage_funded_discount_desc
									}
								}
							}
						}
					}
					treasury = {
						if = {
							limit = {
								OR = {
									has_treasury = no
									NOT = { government_has_flag = government_is_theocracy }
								}
							}
							value = 0
						}
						else = {
							add = {
								desc = pilgrimage_cost_pomp_ceremonial
								add = {
									value = 50
									desc = pilgrimage_cost_pomp_ceremonial
								}
								add = {
									value = 50 
									multiply = activity_cost_scale_by_tier
									subtract = 50
									desc = activity_cost_scale_by_tier_desc
								}
								add = {
									value = 50 
									multiply = activity_cost_scale_by_era
									subtract = 50 
									desc = activity_cost_scale_by_era_desc
								}
								if = {
									limit = {
										dynasty ?= { has_dynasty_perk = ep2_activities_legacy_1 }
									}
									subtract = {
										value = 50
										multiply = ep2_activities_legacy_1_pilgrimages_discount_value
										desc = ep2_activities_legacy_track
									}
								}
								if = {
									limit = {
										has_perk = journey_planner_perk
									}
									multiply = {
										value = voyager_journey_planner_value
										desc = journey_planner_perk_name
									}
								}
								# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) halves this pomp cost.
								if = {
									limit = {
										has_character_modifier = pam_sf_pilgrimage_funded_modifier
									}
									multiply = {
										value = 0.5
										desc = pam_sf_pilgrimage_funded_discount_desc
									}
								}
							}
						}
					}
				}

				#Entourage option grabbing most people suitable from court, + randos.
				travel_entourage_selection = {
					weight = {
						add = pilgrimage_entourage_base_set_weighting_value
						add = pilgrimage_entourage_extras_set_weighting_value
					}

					max = pilgrimage_entourage_pomp_ceremonial_max_value
					invite_rule_order = 1
				}

				ai_will_do = {
					value = 0
					add = {
						value = 40
						desc = "Base test value"
					}
				}
			}
			pilgrimage_pomp_throng = {
				is_shown = { has_dlc_feature = advanced_activities }

				is_valid = {
					pam_vows_of_poverty_premium_activity_option_valid_trigger = yes
				}
				cost = { 
					gold = {
						if = {
							limit = {
								government_has_flag = government_is_theocracy
								has_treasury = yes
							}
							value = 0
						}
						else = {
							add = {
								desc = pilgrimage_cost_pomp_throng
								add = {
									value = 100
									desc = pilgrimage_cost_pomp_throng
								}
								add = {
									value = 100 
									multiply = activity_cost_scale_by_tier
									subtract = 100
									desc = activity_cost_scale_by_tier_desc
								}
								add = {
									value = 100 
									multiply = activity_cost_scale_by_era
									subtract = 100 
									desc = activity_cost_scale_by_era_desc
								}
								if = {
									limit = {
										dynasty ?= { has_dynasty_perk = ep2_activities_legacy_1 }
									}
									subtract = {
										value = 100
										multiply = ep2_activities_legacy_1_pilgrimages_discount_value
										desc = ep2_activities_legacy_track
									}
								}
								if = {
									limit = {
										has_perk = journey_planner_perk
									}
									multiply = {
										value = voyager_journey_planner_value
										desc = journey_planner_perk_name
									}
								}
								# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) halves this pomp cost.
								if = {
									limit = {
										has_character_modifier = pam_sf_pilgrimage_funded_modifier
									}
									multiply = {
										value = 0.5
										desc = pam_sf_pilgrimage_funded_discount_desc
									}
								}
							}
						}
					}
					treasury = {
						if = {
							limit = {
								OR = {
									has_treasury = no
									NOT = { government_has_flag = government_is_theocracy }
								}
							}
							value = 0
						}
						else = {
							add = {
								desc = pilgrimage_cost_pomp_throng
								add = {
									value = 100
									desc = pilgrimage_cost_pomp_throng
								}
								add = {
									value = 100 
									multiply = activity_cost_scale_by_tier
									subtract = 100
									desc = activity_cost_scale_by_tier_desc
								}
								add = {
									value = 100 
									multiply = activity_cost_scale_by_era
									subtract = 100 
									desc = activity_cost_scale_by_era_desc
								}
								if = {
									limit = {
										dynasty ?= { has_dynasty_perk = ep2_activities_legacy_1 }
									}
									subtract = {
										value = 100
										multiply = ep2_activities_legacy_1_pilgrimages_discount_value
										desc = ep2_activities_legacy_track
									}
								}
								if = {
									limit = {
										has_perk = journey_planner_perk
									}
									multiply = {
										value = voyager_journey_planner_value
										desc = journey_planner_perk_name
									}
								}
								# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) halves this pomp cost.
								if = {
									limit = {
										has_character_modifier = pam_sf_pilgrimage_funded_modifier
									}
									multiply = {
										value = 0.5
										desc = pam_sf_pilgrimage_funded_discount_desc
									}
								}
							}
						}
					}
				}
				#Entourage option grabbing sodding everyone suitable from court, + every grabbable rando in the duchy and maybe a few extra.
				travel_entourage_selection = {
					weight = {
						add = pilgrimage_entourage_base_set_weighting_value
						add = pilgrimage_entourage_extras_set_weighting_value
						add = pilgrimage_entourage_sodding_everyone_set_weighting_value
					}

					max = pilgrimage_entourage_pomp_throng_max_value
					invite_rule_order = 1
				}

				ai_will_do = {
					value = 0
					add = {
						value = 40
						desc = "Base test value"
					}
				}
			}
		}
	}

	special_option_category = special_type

	###################
	# PHASES
	###################

	phases = {
		#Solo pilgrimage
		pilgrimage_phase_solo = {
			is_predefined = yes

			cost = {
								gold = {
					if = {
						limit = {
							government_has_flag = government_is_theocracy
							has_treasury = yes
						}
						value = 0
					}
					else = {
					add = {
						value = medium_gold_value
						desc = pilgrimage_cost_distance
						#This needs to be synced  the values in pilgrimage_length_cost_tier_X in the script_values\50_pilgrimage_values.txt file
						if = {
							limit = { exists = scope:province }
							#Tier 0
							if = {
								limit = { "capital_province.squared_distance(scope:province)" <= squared_distance_small }
								subtract = medium_gold_value
							}
							#Tier 1
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_small
									"capital_province.squared_distance(scope:province)" <= squared_distance_medium
								}
								multiply = 0.2
							}
							#Tier 2: Praha -> Cologne
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_medium
									"capital_province.squared_distance(scope:province)" <= squared_distance_large
								}
								multiply = 0.4
							}
							#Tier 3
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_large
									"capital_province.squared_distance(scope:province)" <= squared_distance_huge
								}
								multiply = 0.6
							}
							#Tier 4
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_huge
									"capital_province.squared_distance(scope:province)" <= squared_distance_almost_massive
								}
								multiply = 0.8
							}
							#Tier 5
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_almost_massive
									"capital_province.squared_distance(scope:province)" <= squared_distance_massive
								}
								multiply = 1
							}
							#Tier 6: Klingenberg -> Jerusalem
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_massive
									"capital_province.squared_distance(scope:province)" <= squared_distance_monstrous
								}
								multiply = 1.2
							}
							#Tier 7: Klingenberg -> Kanchipuram
							else_if = {
								limit = { "capital_province.squared_distance(scope:province)" > squared_distance_monstrous }
								multiply = 1.5
							}
						}
						multiply = activity_cost_scale_by_era
						if = {
							limit = {
								exists = scope:province 
								has_character_flag = imaginary_friend_pilgrimage_discount
								any_owned_story = {
									type = story_cycle_imaginary_friend
									var:pilgrimage_destination ?= scope:province
								}
							}
							multiply = {
								value = 0.5
								desc = imaginary_friend_pilgrimage_discount
							}
						}
						#Adventurer
						if = {
							limit = {
								exists = scope:province
								has_government = landless_adventurer_government
								has_perk = clerical_justifications_perk
							}
							multiply = {
								value = 0.5
								desc = adventurer_discount_desc
							}
						}
						# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) halves the distance cost too.
						if = {
							limit = {
								has_character_modifier = pam_sf_pilgrimage_funded_modifier
							}
							multiply = {
								value = 0.5
								desc = pam_sf_pilgrimage_funded_discount_desc
							}
						}
					}
				
					}
				}
				treasury = {
					if = {
						limit = {
							OR = {
								has_treasury = no
								NOT = { government_has_flag = government_is_theocracy }
							}
						}
						value = 0
					}
					else = {
					add = {
						value = medium_gold_value
						desc = pilgrimage_cost_distance
						#This needs to be synced  the values in pilgrimage_length_cost_tier_X in the script_values\50_pilgrimage_values.txt file
						if = {
							limit = { exists = scope:province }
							#Tier 0
							if = {
								limit = { "capital_province.squared_distance(scope:province)" <= squared_distance_small }
								subtract = medium_gold_value
							}
							#Tier 1
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_small
									"capital_province.squared_distance(scope:province)" <= squared_distance_medium
								}
								multiply = 0.2
							}
							#Tier 2: Praha -> Cologne
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_medium
									"capital_province.squared_distance(scope:province)" <= squared_distance_large
								}
								multiply = 0.4
							}
							#Tier 3
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_large
									"capital_province.squared_distance(scope:province)" <= squared_distance_huge
								}
								multiply = 0.6
							}
							#Tier 4
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_huge
									"capital_province.squared_distance(scope:province)" <= squared_distance_almost_massive
								}
								multiply = 0.8
							}
							#Tier 5
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_almost_massive
									"capital_province.squared_distance(scope:province)" <= squared_distance_massive
								}
								multiply = 1
							}
							#Tier 6: Klingenberg -> Jerusalem
							else_if = {
								limit = {
									"capital_province.squared_distance(scope:province)" > squared_distance_massive
									"capital_province.squared_distance(scope:province)" <= squared_distance_monstrous
								}
								multiply = 1.2
							}
							#Tier 7: Klingenberg -> Kanchipuram
							else_if = {
								limit = { "capital_province.squared_distance(scope:province)" > squared_distance_monstrous }
								multiply = 1.5
							}
						}
						multiply = activity_cost_scale_by_era
						if = {
							limit = {
								exists = scope:province 
								has_character_flag = imaginary_friend_pilgrimage_discount
								any_owned_story = {
									type = story_cycle_imaginary_friend
									var:pilgrimage_destination ?= scope:province
								}
							}
							multiply = {
								value = 0.5
								desc = imaginary_friend_pilgrimage_discount
							}
						}
						#Adventurer
						if = {
							limit = {
								exists = scope:province
								has_government = landless_adventurer_government
								has_perk = clerical_justifications_perk
							}
							multiply = {
								value = 0.5
								desc = adventurer_discount_desc
							}
						}
						# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) halves the distance cost too.
						if = {
							limit = {
								has_character_modifier = pam_sf_pilgrimage_funded_modifier
							}
							multiply = {
								value = 0.5
								desc = pam_sf_pilgrimage_funded_discount_desc
							}
						}
					}
				
					}
				}
			}

			ai_will_do = {
				value = 0
				add = {
					value = 30
					desc = "Base test value"
				}
			}

			#This is when you arrive at the pilgrimage destination (and get your Pilgrimage trait)
			on_phase_active = {
				if = {
					limit = { this = scope:host }

					#Promised pilgrimage is now complete
					if = {
						limit = {
							has_character_modifier = promised_pilgrimage_to_clergy_modifier
						}
						send_interface_toast = {
							type = event_toast_effect_good
							title = fulfilled_pilgrimage_promise_tt
							left_icon = scope:host

							remove_character_modifier = promised_pilgrimage_to_clergy_modifier
						}
					}

					if = {
						limit = {
							NOT = { #Hajj progresses once the railroaded hajj events are done
								scope:activity = {
									has_activity_option = {
										category = special_type
										option = pilgrimage_type_hajj
									}
								}
							}
						}
						scope:activity = { progress_activity_phase_after = { months = 3 } }
					}

					scope:activity = {
						set_variable = at_pilgrimage_destination
					}

					#Boost short pilgrimages a bit so they don't always get shafted
					account_for_pilgrimage_length_type_effect = yes
				
					#Keep track of how many unique holy sites we've visited
					save_unique_holy_site_and_update_count_variable_for_tally_effect = { HOLY_SITE = scope:activity.activity_location }
				
					#Keep track of how many pilgrimages we've undertaken for fun stats at the conclusion
					if = {
						limit = { has_variable = num_pilgrimages_undertaken }
						change_variable = {
							name = num_pilgrimages_undertaken
							add = 1
						}	
					}
					
					# Bonus wandering XP from travel_events_bp3.95
					if = {
						limit = {
							has_variable_list = holy_site_dreams
							is_target_in_variable_list = {
								name = holy_site_dreams
								target = root.location.barony
							}
						}
						send_interface_message = {
							type = send_interface_message_good
							title = travel_events_bp3.95.t
							left_icon = root

							if = {
								limit = {
									has_lifestyle = wanderer_lifestyle
								}
								add_wanderer_lifestyle_xp = 500
							}
							stress_and_fulfillment_impact = { 
								base = major_stress_impact_loss 
								zealous = medium_stress_impact_loss
							}
							add_piety = major_piety_gain
						}
					}
				
					#Arrival events - where Pilgrims gain their Pilgrim trait
					#We have the Obligatory option selected - we skip the destination events
					if = {
						limit = {
							scope:activity = {
								has_activity_option = {
									category = pilgrimage_option_fidelity
									option = pilgrimage_fidelity_obligatory
								}
							}
							NOT = { has_character_flag = pilgrimage_counter_obligatory }
						}
						trigger_event = pilgrimage.4010
					}
					#Hajj arrival event - entering Ihram
					else_if = {
						limit = {
							scope:activity = {
								has_activity_option = {
									category = special_type
									option = pilgrimage_type_hajj
								}
							}
						}
						#Railroading the Hajj destination events
						trigger_event = pilgrimage.3101
					}
					#Standard pilgrimage arrival events
					else = {
						trigger_event = { on_action = pilgrimage_arrival_events }
					}
				}
				if = {
					limit = {
						any_owned_story = {
							type = story_cycle_imaginary_friend
							var:pilgrimage_destination ?= scope:activity.activity_location
						}
					}
					trigger_event = {
						id = bp2_yearly.2031
						days = 2 # Fire the event slightly after arrival
					}
				}
				# Achievements.
				if = {
					limit = {
						exists = global_var:started_pathway_to_heaven_achievement
						is_ai = no
					}
					add_to_variable_list = {
						name = pathway_to_heaven_achievement_tally
						target = scope:activity.activity_location.barony
					}
				}
			}

			#Events that happen while we're on site
			on_monthly_pulse = {
				if = {
					limit = { this = scope:host }
					#We are in a Pilgrimage event chain or Hajjing
					if = {
						limit = {
							OR = {
								#Hajj destination events are railroaded via pilgrimage.3101
								scope:activity = {
									has_activity_option = {
										category = special_type
										option = pilgrimage_type_hajj
									}
								}
								#No events until you're done with your chain
								has_character_flag = in_pilgrimage_event_chain 
							}
						} 
						#No events until you're done with your chain
					}
					#We're just doing regular pilgrim destination stuff
					else = {
						trigger_event = { on_action = pilgrimage_destination_events }
					}
				}
			}

			on_end = {
				if = {
					limit = { this = scope:host }
					#If this is our first Hajj
					if = {
						limit = {
							scope:activity = {
								has_activity_option = {
									category = special_type
									option = pilgrimage_type_hajj
								}
							}
							scope:activity.activity_location.county = title:c_mecca
						}
						if = {
							limit = {
								NOT = {
									has_trait = hajjaj
									any_memory = {
										memory_type = completed_hajj_memory
										has_variable = first_hajj
									}
								}
							}
							add_character_flag = {
								flag = should_get_first_hajj_memory
								days = 10 #Fallback in case activity invalidates between here and on_completion
							}
						}
					}
					#Resolve how we did with our type so we can bake that into the total reward
					resolve_pilgrimage_type_reward_effect = yes 
					#Conclusion event
					trigger_event = pilgrimage.7000 
					#Reward effect, looks at if Hajj (in that case looks at if you should get trait or not) or Pilgrimage and award appropriate rewards and log entries
					pilgrimage_completed_log_entry_effect = yes
					# By God Alone - Secular Faith & Rite: a completed pilgrimage lifts a demon's torment (0048).
					if = {
						limit = { has_character_modifier = pam_sf_demon_torment_modifier }
						send_interface_toast = {
							type = event_toast_effect_good
							title = pam_sf_demon_torment_lifted_toast
							left_icon = scope:host
							remove_character_modifier = pam_sf_demon_torment_modifier
							change_spiritual_fulfillment = major_spiritual_fulfillment_value
						}
					}
					# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) warms the sponsor to you on completion.
					if = {
						limit = {
							var:pam_sf_pilgrimage_sponsor ?= { is_alive = yes }
						}
						send_interface_toast = {
							type = event_toast_effect_good
							title = pam_sf_pilgrimage_sponsor_toast
							left_icon = var:pam_sf_pilgrimage_sponsor
							reverse_add_opinion = {
								target = var:pam_sf_pilgrimage_sponsor
								modifier = grateful_opinion
								opinion = 50
							}
						}
						remove_variable = pam_sf_pilgrimage_sponsor
					}
					# By God Alone - Secular Faith & Rite: a realm priest's pledged acclaim (0043) is proclaimed across the capital on completion.
					if = {
						limit = { has_character_modifier = pam_sf_promised_acclaim_modifier }
						send_interface_toast = {
							type = event_toast_effect_good
							title = pam_sf_extolled_pilgrimage_toast
							left_icon = scope:host
							remove_character_modifier = pam_sf_promised_acclaim_modifier
							capital_county ?= {
								add_county_modifier = {
									modifier = pam_sf_extolled_pilgrimage_county_modifier
									years = 15
								}
							}
						}
					}
				}
			}
		}
	}

	###################
	# GUEST HANDLING
	###################

	allow_zero_guest_invites = yes

	can_be_activity_guest = {
		age > 5
		OR = {
			faith.religion = scope:host.faith.religion
			current_travel_plan ?= { travel_plan_owner = scope:host } #When people join you on the way there.
		}
	}

	max_guests = 30

	host_intents = {
		intents = { reflection_intent altruism_intent zealot_intent }
		default = reflection_intent
	}

	guest_intents = {
		intents = { reflection_intent }
		default = reflection_intent
	}

	travel_entourage_selection = {
		weight = standard_travel_entourage_additions
		max = 5
		invite_rule_order = 1
	}

	###################
	# ACTIVITY-SPECIFIC PULSES
	###################

	pulse_actions = {
		entries = {
			apa_preaching_wrath_of_god
			apa_studying_scripture
			apa_visited_markets
			apa_prayer
			apa_silent_contemplation
			apa_preaching_to_unbelievers
			apa_sight_seeing_group
			apa_cultured_discussion
			apa_audience
			apa_communal_prayer
			apa_comet_sighted
			apa_good_omen
			apa_pilgrim_protection
			apa_pilgrim_hospitals
			apa_foreign_custom
			apa_tended_to_travellers
			apa_donated_to_holy_site_temple
			apa_charity_for_the_poor
			apa_spiritual_journey
			apa_picked_up_local_language
			apa_lead_procession
			apa_overcome_with_emotion
			apa_studied_confucian_classics
			apa_passive_religious_learning_pilgrimage_pool
			apa_passive_religious_learning_pilgrimage_rite
		}
		chance_of_no_event = 5
	}

	on_start = {
		#Used for rewards
		if = {
			limit = {
				scope:activity = {
					NOT = { exists = var:pilgrimage_distance }
				}
			}
			set_pilgrimage_distance_variable_effect = {
				PILGRIM = scope:host
				HOLY_SITE = scope:activity.activity_location
			}
		}

		scope:host = {
			#If we had a rebated Pilgrimage, remove the rebate
			if = {
				limit = { has_character_modifier = hunt_urge_for_pilgrim_badges_modifier }
				remove_character_modifier = hunt_urge_for_pilgrim_badges_modifier
			}
			if = {
				limit = { has_character_modifier = ghost_pilgrimage_promised_modifier }
				remove_character_modifier = ghost_pilgrimage_promised_modifier
			}
			if = {
				limit = { has_character_modifier = hajj_promised_modifier }
				remove_character_modifier = hajj_promised_modifier
			}
			if = {
				limit = { has_character_modifier = pilgrimage_promised_modifier }
				remove_character_modifier = pilgrimage_promised_modifier
			}
			# By God Alone - Secular Faith & Rite: a sponsored pilgrimage (0042) - spend the 50% rebate as the journey begins.
			if = {
				limit = { has_character_modifier = pam_sf_pilgrimage_funded_modifier }
				remove_character_modifier = pam_sf_pilgrimage_funded_modifier
			}

			# Keep track of how many pilgrimages we've undertaken for fun stats at the conclusion
			if = {
				limit = {
					NOT = { has_variable = num_pilgrimages_undertaken }
				}
				set_variable = {
					name = num_pilgrimages_undertaken
					value = 0
				}
			}
		}

		scope:activity ?= {
			#Counter for the Activity Special Type (Pious/Worldly etc) Progress bar
			activity_setup_special_type_progression_effect = yes

			#Sets the departure activity log entry
			if = {
				limit = {
					scope:activity = {
						has_activity_option = {
							category = special_type
							option = pilgrimage_type_hajj
						}
					}
					scope:activity.activity_location.county = title:c_mecca
				}
				add_activity_log_entry = {
					key = hajj_departed_log
					score = 25
					tags = { departure }
					character = scope:activity.activity_host
				}
			}
			else = {
				add_activity_log_entry = {
					key = pilgrimage_departed_log
					score = 25
					tags = { departure }
					character = scope:activity.activity_host
				}
			}

			# Check what faith the pilgrimage is supposed to be for.
			set_variable = {
				name = starting_faith
				value = scope:host.faith
			}

			# How jazzed are people about going?
			every_attending_character = {
				limit = {
					this != scope:host
				}
				# Then, apply suitable opinion.
				custom = custom.every_entourage_character
				if = {
					limit = {
						NOT = {
							has_opinion_modifier = {
								modifier = brought_me_on_pilgrimage_opinion
								target = scope:host
							}
						}
					}
					# Very long pilgrimage.
					if = {
						limit = { scope:activity.var:pilgrimage_distance = flag:very_long_pilgrimage_var }
						add_opinion = {
							target = scope:host
							modifier = brought_me_on_pilgrimage_opinion
							opinion = 60
						}
					}
					# Long pilgrimage.
					if = {
						limit = { scope:activity.var:pilgrimage_distance = flag:long_pilgrimage_var }
						add_opinion = {
							target = scope:host
							modifier = brought_me_on_pilgrimage_opinion
							opinion = 45
						}
					}
					# Medium pilgrimage.
					if = {
						limit = { scope:activity.var:pilgrimage_distance = flag:medium_pilgrimage_var }
						add_opinion = {
							target = scope:host
							modifier = brought_me_on_pilgrimage_opinion
							opinion = 30
						}
					}
					# Short pilgrimage.
					if = {
						limit = { scope:activity.var:pilgrimage_distance = flag:short_pilgrimage_var }
						add_opinion = {
							target = scope:host
							modifier = brought_me_on_pilgrimage_opinion
							opinion = 15
						}
					}
				}
			}
		}
	}
	
	on_enter_travel_state = {
		scope:activity ?= {
			# Sort starting travel modifiers.
			# Do we need to apply travel modifiers depending on our activity options?
			## Devotion options.
			if = {
				limit = {
					has_activity_option = {
						category = pilgrimage_option_fidelity
						option = pilgrimage_fidelity_obligatory
					}
					scope:host.current_travel_plan = {
						NOT = { has_travel_plan_modifier = travel_obligatory_pilgrimage_modifier }
					}
				}
				scope:host.current_travel_plan = { add_travel_plan_modifier = travel_obligatory_pilgrimage_modifier }
			}
			else_if = {
				limit = {
					has_activity_option = {
						category = pilgrimage_option_fidelity
						option = pilgrimage_fidelity_contemplative
					}
					scope:host.current_travel_plan = {
						NOT = { has_travel_plan_modifier = travel_contemplative_pilgrimage_modifier }
					}
				}
				scope:host.current_travel_plan = { add_travel_plan_modifier = travel_contemplative_pilgrimage_modifier }
			}
			## Pomp options.
			if = {
				limit = {
					has_activity_option = {
						category = pilgrimage_option_pomp
						option = pilgrimage_pomp_humble
					}
					scope:host.current_travel_plan = {
						NOT = { has_travel_plan_modifier = travel_alone_with_strangers_modifier }
					}
				}
				scope:host.current_travel_plan = { add_travel_plan_modifier = travel_alone_with_strangers_modifier }
			}
		}
	}

	on_travel_state_pulse = {
		#Handled in the on_travel_plan_movement on_action for Pilgrimage and Hajj
	}

	on_enter_passive_state = {
		#If you run the Obligatory activity option, you're going to be early to your own Pilgrimage, so let's progress the phase :eyes:
		voyager_souvenirs_aplenty_effect = yes
		if = {
			limit = { root = scope:host }
			scope:activity = { progress_activity_phase_after = { days = 1 } }
		}
	}

	on_passive_state_pulse = { }

	on_enter_active_state = {
		surveyor_no_stone_unturned_perk_effect = yes
	}

	on_active_state_pulse = { }

	on_complete = {
		#Conclusion/reward event is run in the phase on_end
		#Set up Hajj memories
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = special_type
						option = pilgrimage_type_hajj
					}
				}
				scope:activity.activity_location.county = title:c_mecca
			}
			#For the follow-up reflective event when back home, triggered through travel_plan_completion on_action
			set_variable = {
				name = has_completed_pilgrimage
				value = flag:hajj
			}
			#Add first-Hajj completed memory
			if = {
				limit = { has_character_flag = should_get_first_hajj_memory }
				create_character_memory = { type = completed_hajj_memory }
				remove_character_flag = should_get_first_hajj_memory
				scope:new_memory = {
					set_variable = {
						name = first_hajj
						value = flag:completed_hajj
					}
					set_variable = {
						name = hajj_destination
						value = scope:activity.activity_location
					}
					if = {
						limit = { exists = var:hajj_destination }
						#To prevent 'unused except in loc' errors :catto:
					}
				}
			}
			#Add second-Hajj+ completed memory
			else = {
				create_character_memory = { type = completed_hajj_memory }
				scope:new_memory = {
					set_variable = {
						name = hajj_destination
						value = scope:activity.activity_location
					}
					if = {
						limit = { exists = var:hajj_destination }
						#To prevent 'unused except in loc' errors :catto:
					}
				}
			}
		}
		#Otherwise set up Pilgrimage memories
		else = {
			#For the follow-up reflective event when back home, triggered through travel_plan_completion on_action
			set_variable = {
				name = has_completed_pilgrimage
				value = flag:pilgrimage
			}
			if = {
				limit = { var:has_completed_pilgrimage ?= flag:pilgrimage }
				#To prevent 'unused except in loc' errors :catto:
			}
			#Create a memory of your very first pilgrimage
			if = {
				limit = { 
					NOT = {
						any_memory = {
							memory_type = completed_pilgrimage
							has_variable = first_pilgrimage
						}
					}
				}
				create_character_memory = { type = completed_pilgrimage }
				scope:new_memory = {
					set_variable = {
						name = first_pilgrimage
						value = flag:completed_pilgrimage
					}
					set_variable = {
						name = pilgrimage_destination
						value = scope:activity.activity_location
					}
				}
				if = {
					limit = { exists = var:pilgrimage_distance }
					scope:new_memory = {
						set_variable = {
							name = pilgrimage_length
							value = scope:activity.var:pilgrimage_distance
						} 
						if = {
							limit = { exists = var:pilgrimage_length }
							#To prevent 'unused except in loc' errors :catto:
						}
					}
				}
			}
			#Creates a character memory of the completed pilgrimage with your friend
			else_if = {
				limit = { exists = scope:activity.var:friend_companion }
				create_character_memory = {
					type = completed_pilgrimage_friend 
					participants = { friend = scope:activity.var:friend_companion }
				}
				scope:new_memory = {
					set_variable = {
						name = pilgrimage_destination
						value = scope:activity.activity_location
					} 
				}
			}
			#Creates a character memory of the completed pilgrimage
			else = {
				create_character_memory = { type = completed_pilgrimage }
				scope:new_memory = {
					set_variable = {
						name = pilgrimage_destination
						value = scope:activity.activity_location
					}
					#Save type of pilgrimage for loc - Pious/Worldly
					if = {
						limit = {
							scope:activity = {
								has_activity_option = {
									category = special_type
									option = pilgrimage_type_pious
								}
							}
						}
						set_variable = {
							name = memory_type_of_pilgrimage
							value = flag:pious
						}
					}
					else_if = {
						limit = {
							scope:activity = {
								has_activity_option = {
									category = special_type
									option = pilgrimage_type_worldly
								}
							}
						}
						set_variable = {
							name = memory_type_of_pilgrimage
							value = flag:worldly
						}
					}
					if = {
						limit = { exists = var:pilgrimage_distance }
						set_variable = {
							name = pilgrimage_length
							value = scope:activity.var:pilgrimage_distance
						} 
						if = {
							limit = { exists = var:pilgrimage_length }
							#To prevent 'unused except in loc' errors :catto:
						}
					}
					if = {
						limit = { exists = var:memory_type_of_pilgrimage }
						#To prevent 'unused except in loc' errors :catto:
					}
				}	
			}
		}
		
		# Keep holy-site cooldown tracking unified across all pilgrimage completion memories.
		if = {
			limit = { exists = scope:new_memory }
			scope:new_memory = {
				if = {
					limit = { NOT = { has_variable = pilgrimage_destination } }
					set_variable = {
						name = pilgrimage_destination
						value = scope:activity.activity_location
					}
				}
				set_variable = {
					name = pilgrimage_holy_site_cooldown
					years = 5
				}
			}
		}

		scope:host = {
			# pam_confession_penalty_modifier
			if = {
				limit = { var:pam_confession_penalty_var ?= flag:pilgrimage }
				remove_character_modifier = pam_confession_penalty_modifier
				remove_variable = pam_confession_penalty_var
			}
			if = { # PAM - Catalysts
				limit = {
					has_pam_dlc_trigger = yes
					highest_held_title_tier >= tier_kingdom
					faith.main_rite = { NOT = { rite_has_parameter = forbidden_from_pilgrimage } }
					any_character_situation = {
						situation_type = the_christian_church
						situation_top_has_catalyst = catalyst_the_christian_church_ruler_completed_pilgrimage
					}
				}
				situation:the_christian_church = {
					trigger_situation_catalyst = catalyst_the_christian_church_ruler_completed_pilgrimage
				}
			}
			# tgp_ceremonial_liege_events.0020
			if = {
				limit = {
					var:tgp_ceremonial_liege_events_0020_discount ?= flag:pilgrimage
				}
				tgp_one_up_activity_effect = yes
				remove_variable = tgp_ceremonial_liege_events_0020_discount
			}
			# Dynasty Legacies
			if = {
				limit = {
					# Has the right perk.
					dynasty ?= { has_dynasty_perk = ep2_activities_legacy_1 }
					OR = {
						# Hasn't got this list at all.
						NOT = { has_variable_list = ep2_activities_legacy_1_tracker_list }
						# Or, has the list and meets the requirements.
						AND = {
							has_variable_list = ep2_activities_legacy_1_tracker_list
							variable_list_size = {
								name = ep2_activities_legacy_1_tracker_list
								value <= ep2_activities_legacy_1_pilgrimages_learning_visitable_holy_sites_cap_value
							}
							NOT = {
								is_target_in_variable_list = {
									name = ep2_activities_legacy_1_tracker_list
									target = scope:activity.activity_location.county
								}
							}
						}
					}
				}
				# Add the appropriate learning.
				add_learning_skill = ep2_activities_legacy_1_pilgrimages_learning_learning_per_holy_site_value
				# Plus add the new target.
				add_to_variable_list = {
					name = ep2_activities_legacy_1_tracker_list
					target = scope:activity.activity_location.county
				}
			}
		}
	}

	###################
	# GRAPHICS
	###################
	header_background = { #Islam
		trigger = { religion = religion:islam_religion }
		reference = "gfx/interface/illustrations/activity_header_backgrounds/activity_pilgrimage.dds"
	}
	header_background = { #Judaism
		trigger = { religion = religion:judaism_religion }
		reference = "gfx/interface/illustrations/event_scenes/ep2_holysite_jerusalem.dds"
	}
	header_background = { #Orthodox Christianity
		trigger = { faith = faith:orthodox }
		reference = "gfx/interface/illustrations/event_scenes/ep3_holysite_orthodox.dds"
	}
	header_background = { #Other Christianity
		trigger = { religion = religion:christianity_religion }
		reference = "gfx/interface/illustrations/event_scenes/ep2_holysite_western.dds"
	}
	header_background = { #Zoroastrianism
		trigger = { religion = religion:zoroastrianism_religion }
		reference = "gfx/interface/illustrations/event_scenes/fp3_temple.dds"
	}
	header_background = { #East Asian faiths
		trigger = {
			OR = {
				faith.religion = { is_in_family = rf_sinitic }
				religion = religion:shintoism_religion
				AND = {
					faith.religion = { is_in_family = rf_eastern }
					culture = { has_graphical_east_asia_culture_group_trigger = yes }
				}
			}
		}
		reference = "gfx/interface/illustrations/event_scenes/tgp_holysite_asia.dds"
	}
	header_background = { #Dharmic / Indian faiths
		trigger = { faith.religion = { is_in_family = rf_eastern } }
		reference = "gfx/interface/illustrations/event_scenes/ep2_holysite_indian.dds"
	}
	header_background = { #Steppe folk faiths
		trigger = {
			OR = {
				religion = religion:tengrism_religion
				religion = religion:magyar_religion
				religion = religion:siberian_religion
				religion = religion:kamuyism_religion
			}
		}
		reference = "gfx/interface/illustrations/event_scenes/mpo_temple_steppe.dds"
	}
	header_background = { #Norse / Germanic pagan
		trigger = {
			faith.religion = { is_in_family = rf_pagan }
			culture = { has_graphical_norse_culture_group_trigger = yes }
		}
		reference = "gfx/interface/illustrations/event_scenes/fp1_tribal_temple.dds"
	}
	header_background = { #Other pagan / folk faiths
		trigger = { faith.religion = { is_in_family = rf_pagan } }
		reference = "gfx/interface/illustrations/event_scenes/ep2_holysite_tribal.dds"
	}
	header_background = "gfx/interface/illustrations/event_scenes/temple.dds" #Fallback

	# Travel
	background = { # Bridge
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				is_riverside_province = yes
				geographical_region = world_europe
				OR = {
					terrain = farmlands
					terrain = plains
					terrain = mountains
					terrain = hills
				}
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_bridge.dds"
		environment = "environment_travel_bridge"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}

	background = { #Rice Fields - If we have Paddy fields AND/or terraced hills
	#This goes before other terrain since it can override in many different terrains if built
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				terrain = farmlands
				OR = {
					terrain = terraced_hills
					has_building_or_higher = paddy_fields_01
				}
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/tgp_rice_fields.dds"
		environment = "environment_tgp_rice_fields"
		ambience = "event:/DLC/EP4/SFX/Events/Event_Backgrounds/tgp_rice_fields"
	}

	background = { #Farmlands - East Asia
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				terrain = farmlands
				culture = { has_graphical_east_asia_culture_group_trigger = yes }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/tgp_farm_asia.dds"
		environment = "environment_tgp_farm_asia"
		ambience = "event:/DLC/EP4/SFX/Events/Event_Backgrounds/tgp_farm_asia"
	}
	
	background = { # Farmland, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				terrain = farmlands
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_farm.dds"
		environment = "environment_travel_farmlands"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	background = { # Farmland, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				terrain = farmlands
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/farms.dds"
		environment = "environment_event_farms"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}

	background = { #Desert, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_desert_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_desert.dds"
		environment = "environment_travel_desert"
		ambience = "event:/SFX/Events/Backgrounds/desert_day"
	}
	background = { #Desert, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_desert_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/desert.dds"
		environment = "environment_event_bp1_desert"
		ambience = "event:/SFX/Events/Backgrounds/desert_day"
	}

	background = { #forest snowy
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location ?= { hunt_snowy_forest_trigger = yes }
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_hunt_snowy_forest.dds"
		environment = "environment_hunt_snowy_forest"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}

	background = { #forest_pine
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_forest_pine_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/forest_pine.dds"
		environment = "environment_event_forest_pine"
		ambience = "event:/SFX/Events/Backgrounds/coniferous_forest_day"
	}

	background = { #forest
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_forest_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/forest.dds"
		environment = "environment_event_forest"
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	background = { #mountains, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_mountains_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_mountains.dds"
		environment = "environment_travel_mountain_settlement"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}
	background = { #mountains, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_mountains_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/mountains.dds"
		environment = "environment_event_mountains"
		ambience = "event:/SFX/Events/Backgrounds/mountains_day"
	}

	background = { #steppe, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_steppe_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_steppe.dds"
		environment = "environment_travel_steppe_settlement"
		ambience = "event:/SFX/Events/Backgrounds/steppe_day"
	}
	background = { #steppe, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_steppe_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/steppe.dds"
		environment = "environment_event_steppe"
		ambience = "event:/SFX/Events/Backgrounds/steppe_day"
	}

	background = { #drylands (formerly desert)
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_drylands_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/drylands.dds"
		environment = "environment_event_desert"
		ambience = "event:/SFX/Events/Backgrounds/desert_day"
	}

	background = { #wetlands
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_wetlands_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_wetlands.dds"
		environment = "environment_event_bp1_wetlands" 
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	background = { #jungle
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_wilderness_jungle_trigger = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_jungle.dds"
		environment = "environment_event_bp1_jungle"
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	background = { #plains, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_plains_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_hills.dds"
		environment = "environment_travel_hills_settlement"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	background = { #plains, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_plains_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_plains.dds"
		environment = "environment_event_bp1_plains"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}

	background = { #hills, settled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_hills_trigger = yes
				exists = province_owner
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_travel_hills.dds"
		environment = "environment_travel_hills_settlement"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	background = { #hills, unsettled
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				graphical_hills_trigger = yes
				NOT = { exists = province_owner }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/bp1_hills.dds"
		environment = "environment_event_bp1_hills"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}

	background = { #sea
		trigger = {
			scope:host.location != scope:activity.activity_location
			scope:host.location = {
				is_sea_province = yes
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/fp1_ocean.dds"
		environment = "environment_event_fp1_ocean"
		ambience = "event:/DLC/FP1/SFX/Events/event_ocean_longship"
	}
	# End Travel
	#Unique holy sites
	background = {
		trigger = {
			activity_location.county = title:c_mecca
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_holysite_mecca.dds"
		environment = "environment_mecca"
		ambience = "event:/SFX/Events/Backgrounds/town_market_middleeastern_day"
	}
	background = { #Jerusalem
		trigger = {
			activity_location.county = title:c_jerusalem
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_holysite_jerusalem.dds"
		environment = "environment_jerusalem"
		ambience = "event:/SFX/Events/Backgrounds/town_market_middleeastern_day"
	}
	background = { #Constantinople
		trigger = {
			activity_location.county = title:c_byzantion
		}
		texture = "gfx/interface/illustrations/event_scenes/ep3_hagia_sophia.dds"
		environment = "environment_ep3_hagia_sophia"
		ambience = "event:/DLC/EP3/SFX/Events/Event_Images/ep3_evn_eventimage_hagia_sophia"
	}
	#Generic holy sites
	background = {
		trigger = {
			scope:host = {
				OR = {
					religion = religion:tengrism_religion
					religion = religion:magyar_religion
					religion = religion:siberian_religion
					religion = religion:kamuyism_religion
				}
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/mpo_temple_steppe.dds"
		environment = "environment_mpo_temple_steppe" 
		ambience = "event:/DLC/CE2/Events/Event_Images/mpo_temple_steppe"
	}
	background = {
		trigger = { scope:host.religion = religion:zoroastrianism_religion }
		texture = "gfx/interface/illustrations/event_scenes/fp3_temple.dds"
		environment = "environment_event_fp3_temple"
		ambience = "event:/DLC/FP1/SFX/Events/event_temple"
	}
	background = { #East Asia
		trigger = {
			scope:host = {
				faith.religion = {
					OR = {
						is_in_family = rf_eastern
						is_in_family = rf_sinitic
						this = religion:shintoism_religion
					}
				}
				culture = {
					has_graphical_east_asia_culture_group_trigger = yes
				}
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/tgp_holysite_asia.dds"
		environment = "environment_tgp_holysite_asia"
		ambience = "event:/DLC/EP4/SFX/Events/Event_Backgrounds/tgp_holysite_asia"
	}
	background = { #Christian - Grand Cathedral Eastern (high clergy)
		trigger = {
			trigger_if = {
				limit = {
					activity_location.county.faith.religion = religion:christianity_religion
				}
				activity_location.county = { pam_is_eastern_christian_trigger = yes }
			}
			trigger_else = {
				scope:host = { pam_is_eastern_christian_trigger = yes }
			}
			scope:host = { pam_church_event_background_is_grand_eastern_trigger = yes }
		}
		texture = "gfx/interface/illustrations/event_scenes/ep3_hagia_sophia.dds"
		environment = "environment_ep3_hagia_sophia"
		ambience = "event:/DLC/EP3/SFX/Events/Event_Images/ep3_evn_eventimage_hagia_sophia"
	}
	background = {
		trigger = {
			trigger_if = {
				limit = {
					activity_location.county.faith.religion = religion:christianity_religion
				}
				activity_location.county = { pam_is_eastern_christian_trigger = yes }
			}
			trigger_else = {
				scope:host = { pam_is_eastern_christian_trigger = yes }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep3_holysite_orthodox.dds"
		environment = "environment_ep3_holysite_orthodox"
		ambience = "event:/DLC/EP3/SFX/Events/Event_Images/ep3_evn_eventimage_orthodox_holy_site"
	}
	background = {
		trigger = {
			activity_location.culture = {
				OR = {
					has_graphical_mena_culture_group_trigger = yes
					has_graphical_iranian_culture_group_trigger = yes
				}
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_holysite_mena.dds"
		environment = "environment_generic_holy_site_mena"
		ambience = "event:/SFX/Events/Backgrounds/town_market_middleeastern_day"
	}
	background = {
		trigger = {
			activity_location.culture = { has_graphical_india_culture_group_trigger = yes }
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_holysite_indian.dds"
		environment = "environment_indian_holy_site"
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}
	background = {
		trigger = {
			activity_location.culture = { has_graphical_iberian_culture_group_trigger = yes }
		}
		texture = "gfx/interface/illustrations/event_scenes/fp2_temple.dds"
		environment = "environment_event_fp2_temple"
		ambience = "event:/DLC/FP2/SFX/Events/temple"
	}
	background = { #Western Christian - Gothic exterior
		trigger = {
			scope:host = { pam_church_event_background_is_grand_western_trigger = yes }
			current_year >= 900
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_wedding_ceremony_western.dds"
		environment = "environment_western_wedding"
		ambience = "event:/SFX/Events/Backgrounds/temple_christian"
	}
	background = { #Western Christian - Mediterranean or urban Romanesque exterior
		trigger = {
			scope:host = {
				pam_is_western_christian_trigger = yes
				pam_church_event_background_is_developed_trigger = yes
			}
			activity_location = { pam_church_background_location_is_mediterranean_or_urban_trigger = yes }
			current_year >= 900
		}
		texture = "gfx/interface/illustrations/event_scenes/pam_romanesque_church_exterior.dds"
		environment = "environment_pam_romanesque_church_exterior"
		ambience = "event:/DLC/CE3/SFX/Events/romanesque_church_exterior" #AUDIO CE3
	}
	background = { #Western Christian - Green Romanesque exterior
		trigger = {
			scope:host = {
				pam_is_western_christian_trigger = yes
				pam_church_event_background_is_developed_trigger = yes
			}
			current_year >= 900
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_holysite_western.dds"
		environment = "environment_western_holy_site"
		ambience = "event:/SFX/Events/Backgrounds/temple_christian"
	}
	background = { #Western Christian - Pre-Romanesque exterior
		trigger = {
			scope:host = { pam_is_western_christian_trigger = yes }
			NOT = { activity_location.culture = { has_graphical_norse_culture_group_trigger = yes } }
		}
		texture = "gfx/interface/illustrations/event_scenes/pam_pre-romanesque_church_exterior.dds"
		environment = "environment_pam_preromanesque_church_exterior"
		ambience = "event:/DLC/CE3/SFX/Events/pre-romanesque_church_exterior" #AUDIO CE3
	}
	background = {
		trigger = {
			activity_location.culture = {
				OR = {
					has_graphical_western_culture_group_trigger = yes
					has_graphical_mediterranean_culture_group_trigger = yes
				}
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_holysite_western.dds"
		environment = "environment_western_holy_site"
		ambience = "event:/SFX/Events/Backgrounds/temple_christian"
	}
	background = {
		trigger = {
			OR = {
				activity_location.province_owner ?= { 
					OR = {
						government_has_flag = government_is_clan
						government_has_flag = government_is_tribal
					} 
				}
				activity_location.culture = { has_graphical_steppe_culture_group_trigger = yes }
			}
		}
		texture = "gfx/interface/illustrations/event_scenes/ep2_holysite_tribal.dds"
		environment = "environment_event_garden"
		ambience = "event:/DLC/FP1/SFX/Events/event_temple"
	}
	background = {
		trigger = {
			activity_location.culture = { has_graphical_norse_culture_group_trigger = yes }
		}
		texture = "gfx/interface/illustrations/event_scenes/fp1_tribal_temple.dds"
		environment = "environment_event_fp1_tribal_temple"
		ambience = "event:/DLC/FP1/SFX/Events/event_temple"
	}
	background = {
		trigger = { 
			scope:host.rite = { rite_has_tenet = tenet_sanctity_of_nature }
		}
		texture = "gfx/interface/illustrations/event_scenes/forest.dds"
		environment = "environment_event_forest"
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}
	background = {
		trigger = { scope:host.religion = religion:tengrism_religion }
		texture = "gfx/interface/illustrations/event_scenes/forest.dds"
		environment = "environment_event_forest"
		ambience = "event:/SFX/Events/Backgrounds/deciduous_forest_day"
	}

	#Fallback
	background = {
		texture = "gfx/interface/illustrations/event_scenes/temple.dds"
		environment = "environment_event_temple"
		ambience = "event:/SFX/Events/Backgrounds/temple_generic"
	}

	### Plug in widgets
	activity_window_widgets = {
		activity_special_type_progression = "activity_plugin_widgets_summary"
	}

	window_characters = {

		pilgrim = {
			camera = camera_body_left
			
			effect = {
				if = {
					limit = {
						has_activity_option = {
							category = pilgrimage_option_pomp
							option = pilgrimage_pomp_throng
						}
					}
					every_attending_character = {
						limit = {
							this != scope:host
							OR = {
								scope:host.location = scope:activity.activity_location
								scope:host.location = { is_sea_province = yes }
							}
						}
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = {
						scope:character = {
							OR = {
								has_trait = cynical
								any_secret = { type = secret_non_believer }
							}
						}
					}
					animation = { boredom personality_cynical worry personality_vengeful dismissal }
				}
				triggered_animation = {
					trigger = {
						scope:character = { always = yes }
					}
					animation = { personality_forgiving survey prostration }
				}
			}
		}

		pilgrim = {
			camera = camera_body
			
			effect = {
				every_attending_character = {
					limit = {
						this != scope:host
						OR = {
							scope:host.location = scope:activity.activity_location
							scope:host.location = { is_sea_province = yes }
						}
					}
					add_to_list = characters
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = {
						scope:character = {
							OR = {
								has_trait = cynical
								any_secret = { type = secret_non_believer }
							}
						}
					}
					animation = { boredom personality_cynical worry personality_vengeful dismissal }
				}
				triggered_animation = {
					trigger = {
						scope:character = { always = yes }
					}
					animation = { personality_compassionate chaplain reading }
				}
			}
		}

		pilgrim = { # Travel
			camera = camera_activity_horse
			
			effect = {
				if = {
					limit = {
						has_activity_option = {
							category = pilgrimage_option_pomp
							option = pilgrimage_pomp_throng
						}
					}
					every_attending_character = {
						limit = {
							this != scope:host
							NOR = {
								scope:host.location = scope:activity.activity_location
								scope:host.location = { is_sea_province = yes }
							}
						}
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				animation = jockey_walk
			}
		}

		pilgrim = { # Travel
			camera = camera_activity_horse
			
			effect = {
				every_attending_character = {
					limit = {
						this != scope:host
						NOR = {
							scope:host.location = scope:activity.activity_location
							scope:host.location = { is_sea_province = yes }
						}
					}
					add_to_list = characters
				}
			}

			scripted_animation = {
				animation = jockey_walk
			}
		}
		
		host = {
			camera = camera_body
			
			effect = {
				if = {
					limit = {
						OR = {
							scope:host.location = scope:activity.activity_location
							scope:host.location = { is_sea_province = yes }
						}
					}
					scope:host = { add_to_list = characters }
				}
			}
			scripted_animation = {
				triggered_animation = {
					trigger = {
						scope:character.location = { is_sea_province = yes }
					}
					animation = { survey }
				}
				triggered_animation = {
					trigger = {
						scope:host = {
							OR = {
								has_trait = cynical
								any_secret = { type = secret_non_believer }
							}
						}
					}
					animation = { personality_cynical }
				}
				#Fallback
				animation = prayer
			}
		}
		
		travel_host = {
			camera = camera_activity_horse
			
			effect = {
				if = {
					limit = {
						NOR = {
							scope:host.location = scope:activity.activity_location
							scope:host.location = { is_sea_province = yes }
						}
					}
					scope:host = {
						add_to_list = characters
					}
				}
			}
			scripted_animation = {
				triggered_animation = {
					trigger = { scope:character = { has_trait = impatient } }
					animation = { jockey_gallop }
				}
				animation = jockey_walk
			}
		}

		pilgrim = {
			camera = camera_body_right
			
			effect = {
				every_attending_character = {
					limit = {
						this != scope:host
						OR = {
							scope:host.location = scope:activity.activity_location
							scope:host.location = { is_sea_province = yes }
						}
					}
					add_to_list = characters
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = {
						scope:character = {
							OR = {
								has_trait = cynical
								any_secret = { type = secret_non_believer }
							}
						}
					}
					animation = { boredom personality_cynical worry personality_vengeful dismissal }
				}
				triggered_animation = {
					trigger = {
						scope:character = { always = yes }
					}
					animation = { page_flipping personality_content holding_staff }
				}
			}
		}

		pilgrim = {
			camera = camera_body_right
			
			effect = {
				if = {
					limit = {
						has_activity_option = {
							category = pilgrimage_option_pomp
							option = pilgrimage_pomp_throng
						}
					}
					every_attending_character = {
						limit = {
							this != scope:host
							OR = {
								scope:host.location = scope:activity.activity_location
								scope:host.location = { is_sea_province = yes }
							}
						}
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				triggered_animation = {
					trigger = {
						scope:character = {
							OR = {
								has_trait = cynical
								any_secret = { type = secret_non_believer }
							}
						}
					}
					animation = { boredom personality_cynical worry personality_vengeful dismissal }
				}
				triggered_animation = {
					trigger = {
						scope:character = { always = yes }
					}
					animation = { stunned pondering survey_staff }
				}
			}
		}

		pilgrim = { # Travel
			camera = camera_body
			
			effect = {
				every_attending_character = {
					limit = {
						this != scope:host
						NOR = {
							scope:host.location = scope:activity.activity_location
							scope:host.location = { is_sea_province = yes }
						}
					}
					add_to_list = characters
				}
			}

			scripted_animation = {
				animation = jockey_walk
			}
		}

		pilgrim = { # Travel
			camera = camera_activity_horse
			
			effect = {
				if = {
					limit = {
						has_activity_option = {
							category = pilgrimage_option_pomp
							option = pilgrimage_pomp_throng
						}
					}
					every_attending_character = {
						limit = {
							this != scope:host
							NOR = {
								scope:host.location = scope:activity.activity_location
								scope:host.location = { is_sea_province = yes }
							}
						}
						add_to_list = characters
					}
				}
			}

			scripted_animation = {
				animation = jockey_walk
			}
		}
	}
}
